import { Injectable } from '@angular/core';

import {HttpClient,HttpHeaders,HttpParams} from '@angular/common/http';
import { Storage } from '@ionic/storage';
import 'rxjs/add/operator/toPromise';
@Injectable()
export class UsersService {
  url:string='http://115.159.104.128:3000/users';

   constructor(
    private http:HttpClient,
    private storage:Storage
  ) {

  }


  login(user):Promise<any>{
    return this.http.post(this.url+'/login',user).toPromise().then((data)=> data)
  }

  register(user):Promise<any>{
    return this.http.post(this.url+'/regist',user).toPromise().then((data)=> data);

  }

  getCodeByphone(user):Promise<any>{
    // const that=this;
    // alert(that.url);
    /////////////////////////'/check'//////////////
    return this.http.post(this.url+'/check',user).toPromise().then((data)=> data);

  }

  // login(user,callback){
  //   this.http.post(this.url+'/login',user).subscribe(
  //     function (result) {
  //       callback(result);
  //     function (error) {
  //     },
  //       console.log(error.message);
  //     }
  //   )
  // }
  getFocusHouses(user,callback){
    this.http.post(this.url+'/getFocusHouses',user).subscribe(
      function (result) {
        callback(result);
      },
      function (error) {
        console.log(error.message);
      }
    )
  }

  getRecord(user,callback){
    this.http.post(this.url+'/getRecord',user).subscribe(
      function (result) {
        callback(result);
      },
      function (error) {
        console.log(error.message);
      }
    )
  }
//获取看房信息（用户）
  getMyRecord(user,callback){
    this.http.post(this.url+'/getMyRecord',user).subscribe(
      function (result) {
        callback(result);
      },
      function (error) {
        console.log(error.message);
      }
    )
  }

//删除信息
  delRecord(arrInfo,callback){
    this.http.post(this.url+'/delRecord',arrInfo).subscribe(
      function (result) {
        console.log(result)
        callback(result);
      },
      function (error) {
        console.log(error.message);
      }
    )
  }


  //按照arrangeId删除信息
  delRecordByarrId(arrInfo,callback){
    this.http.post(this.url+'/delRecordByarrId',arrInfo).subscribe(
      function (result) {
        console.log(result)
        callback(result);
      },
      function (error) {
        console.log(error.message);
      }
    )
  }

  getMyHouses(user,callback){
    this.http.post(this.url+'/getMyHouses',user).subscribe(
      function (result) {
        callback(result);
      },
      function (error) {
        console.log(error.message);
      }
    )
  }







  addUser(){

  }



  getUserInfo(user,callback){
    this.http.post(this.url+'/getUserInfo',user).subscribe(
      function (result) {
        callback(result);
      },
      function (error) {
        console.log(error.message);
      }
    )
  }

  editUser(user,callback){
    this.http.post(this.url+'/editUser',user).subscribe(
      function (result) {
        callback(result);
      },
      function (error) {
        console.log(error.message);
      }
    )
  }
  editPass(user,callback){
    console.log(user)
    this.http.post(this.url+'/editPass',user).subscribe(
      function (result) {
        callback(result);
      },
      function (error) {
        console.log(error.message);
      }
    )
  }

}
